<!--  -->
<template>
  <div class="container flex-column ">
    <el-tabs v-model="activeTab">
      <el-tab-pane
        v-for="item in tabsArr"
        :key="item.id"
        :label="item.name"
        :name="item.key"
      ></el-tab-pane>
    </el-tabs>

    <div class="flex-sub " v-if="activeTab === tabsEmun.PERSON">
      <div class="btn-container flex-row justify-between align-center ">
        <!-- 添加按钮 -->
        <el-dropdown trigger="click" @command="handleCommand">
          <custom-button title="添加名单" class="custom-btn" />
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item
              v-for="item in personDropdownList"
              :key="item.id"
              :command="item.identityEnum"
            >
              {{ item.name }}
            </el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>

        <el-input v-model="personKeyword" class="input-width" placeholder="请输入关键字搜索">
          <div slot="suffix" class="el-icon-search search-button" @click="handleSearch"></div>
        </el-input>
      </div>
      <person-list ref="personList" :keyword="personKeyword" />
    </div>
    <div class="flex-sub" v-if="activeTab === tabsEmun.VEHICLE">
      <div class="btn-container flex-row align-center justify-between">
        <!-- 添加按钮 -->
        <el-dropdown trigger="click" @command="handleCarCommang">
          <custom-button title="添加名单" class="custom-btn" />
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item
              v-for="item in vehicleDropdownList"
              :key="item.id"
              :command="item.identityEnum"
            >
              {{ item.name }}
            </el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
        <el-input v-model="vehicleKeyword" class="input-width" placeholder="请输入关键字搜索">
          <div slot="suffix" class="el-icon-search search-button" @click="handleSearch"></div>
        </el-input>
      </div>
      <vehicle-list ref="vehicleList" :keyword="vehicleKeyword" />
    </div>

    <edit-dialog
      :isShow="isShowEdit"
      :identityEnum="identityEnum"
      :isPerson="isPerson"
      @close="isShowEdit = false"
      @add="handleAdd"
    />
  </div>
</template>

<script>
import PersonList from './components/person-list.vue'
import vehicleList from './components/vehicle-list'
import EditDialog from './components/edit-dialog.vue'

const IDENTITY_ENUM = {
  INTERNAL_MEMBER: 'INTERNAL_MEMBER',
  VISITOR: 'VISITOR',
}

export default {
  components: { PersonList, vehicleList, EditDialog },

  data() {
    return {
      personKeyword: '',
      vehicleKeyword: '',
      activeTab: '',
      identityEnum: '',
      isShowEdit: false,
      isPerson: true,
    }
  },
  created() {
    this.activeTab = this.tabsEmun.PERSON
  },

  computed: {
    tabsArr() {
      return [
        { id: 0, name: '人员名单', key: 'person' },
        { id: 1, name: '车辆名单', key: 'vehicle' },
      ]
    },
    tabsEmun() {
      return {
        PERSON: 'person',
        VEHICLE: 'vehicle',
      }
    },
    personDropdownList() {
      return [
        { id: 0, name: '添加园内人员', identityEnum: IDENTITY_ENUM.INTERNAL_MEMBER },
        // { id: 1, name: '添加访客人员', identityEnum: IDENTITY_ENUM.VISITOR },
      ]
    },
    vehicleDropdownList() {
      return [
        { id: 0, name: '添加园区车辆', identityEnum: IDENTITY_ENUM.INTERNAL_MEMBER },
        // { id: 1, name: '添加访客车辆', identityEnum: IDENTITY_ENUM.VISITOR },
      ]
    },
  },

  methods: {
    handleSearch() {
      switch (this.activeTab) {
        case this.tabsEmun.PERSON:
          this.$refs.personList && this.$refs.personList.getTableData()
          break
        case this.tabsEmun.VEHICLE:
          this.$refs.vehicleList && this.$refs.vehicleList.getTableData()
          break
      }
    },
    handleCommand(value) {
      this.isPerson = true
      this.identityEnum = value
      // TODO 打开添加对话框
      this.isShowEdit = true
    },
    handleCarCommang(value) {
      this.isPerson = false

      this.identityEnum = value
      // TODO 打开添加对话框
      this.isShowEdit = true
    },
    handleAdd() {
      if (this.isPerson) {
        this.$refs.personList.getTableData()
      } else {
        this.$refs.vehicleList.getTableData()
      }

      this.isShowEdit = false
    },
  },
}
</script>
<style lang="scss" scoped>
.container {
  width: 100%;
  height: 100%;
  // padding: 20px;
  padding: vw(20px);
  background: #fff;
  box-sizing: border-box;
}

.query-container {
  height: vh(70px);
  padding: 0 vw(20px);
  overflow: hidden;
  box-sizing: border-box;
}

.btn-edit {
  color: #0084ee;

  &:hover {
    cursor: pointer;
    opacity: 0.7;
  }
}

.btn-delete {
  color: #d12d1f;

  &:hover {
    cursor: pointer;
    opacity: 0.7;
  }
}

.line {
  width: 100%;
  height: vh(10px);
  background: #f3f4f8;
}

::v-deep .el-form-item {
  margin-bottom: 0;
}

.table-container {
  padding: vw(20px);
}

::v-deep .el-tabs__nav .is-top {
  // margin-left: vw(30px);
}

::v-deep .el-tabs__active-bar {
  height: 3px;
  background: #d12d1f;
}

::v-deep .el-tabs__nav-wrap::after {
  height: 1px;
}

::v-deep .el-table__row {
  color: #999;
}

.tab {
  padding: 0 vw(20px);
  margin-top: vh(10px);
}

.custom-btn {
  // margin-left: vw(20px);
}

::v-deep .el-tabs__header {
  margin: 0;
}

.btn-container {
  padding-top: vw(20px);
  padding-bottom: vw(20px);
}

.input-width {
  width: vw(350px);
  // height: vh(50px);
}

.search-button {
  height: 100%;
  padding-top: vh(8px);
  padding-right: vw(6px);
  line-height: 100%;
  cursor: pointer;
}

.table-data-container {
  width: 100%;
  height: 100%;
  padding: 0 vw(20px);
}
</style>
